# Maintainer: David Runge <dvzrv@archlinux.org>
# Maintainer: Daniel M. Capella <polyzen@archlinux.org>

pkgname=khard
pkgver=0.18.0
pkgrel=2
pkgdesc="Console address book manager"
arch=('any')
url="https://github.com/lucc/khard"
license=('GPL3')
depends=('python-atomicwrites' 'python-configobj' 'python-ruamel-yaml'
         'python-unidecode' 'python-vobject')
makedepends=('python-build' 'python-installer' 'python-setuptools-scm'
             'python-sphinx' 'python-sphinx-autoapi'
             'python-sphinx-autodoc-typehints' 'python-wheel')
checkdepends=('python-pytest')
optdepends=('vdirsyncer: Synchronization of address books with a DAV server'
            'diffutils: Using sdiff_khard_wrapper.sh')
source=("https://files.pythonhosted.org/packages/source/${pkgname::1}/${pkgname}/${pkgname}-${pkgver}.tar.gz")
sha256sums=('fe88d4b47fdd948610ac573c01fa13d1b7996265cbc44391085761af9a030615')
b2sums=('856190b5972c6b912977a69a4786779d59fafbdea1bc323c8ca8af56c7ce33e09efbe58734db261437ea0e654a8457086174becedb76dacf802f975847e03c63')

build() {
  cd "$pkgname-$pkgver"
  python -m build --wheel --skip-dependency-check --no-isolation
  make -C doc man
}

check() {
  cd "$pkgname-$pkgver"
  pytest -v
}

package() {
  cd "$pkgname-$pkgver"
  python -m installer --destdir="$pkgdir" dist/*.whl
  # additional wrapper script
  install -vDm 755 "misc/sdiff/sdiff_${pkgname}_wrapper.sh" \
    "${pkgdir}/usr/lib/${pkgname}/sdiff_${pkgname}_wrapper.sh"
  # twinkle integration
  install -vDm 644 misc/twinkle/scripts/*.py \
    -t "${pkgdir}/usr/share/${pkgname}/twinkle/scripts/"
  install -vDm 644 misc/twinkle/sounds/*.ogg \
    -t "${pkgdir}/usr/share/${pkgname}/twinkle/sounds/"
  # zsh
  install -vDm 644 "misc/zsh/_"*"${pkgname}" \
    -t "${pkgdir}/usr/share/zsh/site-functions/"
  # docs
  install -vDm 644 {CHANGES,CONTRIBUTING.rst,README.md} \
    -t "${pkgdir}/usr/share/doc/${pkgname}/"
  # man
  install -vDm 644 "doc/build/man/${pkgname}.1" \
    -t "${pkgdir}/usr/share/man/man1"
  install -vDm 644 "doc/build/man/${pkgname}.conf.5" \
    -t "${pkgdir}/usr/share/man/man5"
}
